package com.info.game;

import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.Manifold;
import com.engine.game.GameObject;

public class FancyRobotsContactListener implements ContactListener{

	@Override
	public void beginContact(Contact contact) {
		
		Object obj1 = contact.getFixtureA().getBody().getUserData();
		Object obj2 = contact.getFixtureB().getBody().getUserData();
		
		GameObject game1 = (GameObject) obj1;
		GameObject game2 = (GameObject) obj2;
		
		game1.getPhysics().collisionWith(game1, game2.name);
		game2.getPhysics().collisionWith(game2, game1.name);
		
		
		
		
		
		
		if(contact.getFixtureA().getUserData().equals("FOOT_SENSOR_LOW")){
			
			GravityRobotPhysicsComponent.numFootContactsLow++;
		}
		else if(contact.getFixtureB().getUserData().equals("FOOT_SENSOR_LOW")){
			
			GravityRobotPhysicsComponent.numFootContactsLow++;
		}
		
		if(contact.getFixtureA().getUserData().equals("FOOT_SENSOR_UP")){
			
			GravityRobotPhysicsComponent.numFootContactsUp++;
		}
		else if(contact.getFixtureB().getUserData().equals("FOOT_SENSOR_UP")){
			
			GravityRobotPhysicsComponent.numFootContactsUp++;
		}
		
		
	}

	@Override
	public void endContact(Contact contact) {
		
		Object obj1 = contact.getFixtureA().getBody().getUserData();
		Object obj2 = contact.getFixtureB().getBody().getUserData();
		
		GameObject game1 = (GameObject) obj1;
		GameObject game2 = (GameObject) obj2;
		
		game1.getPhysics().endCollisionWith(game1, game2.name);
		game2.getPhysics().endCollisionWith(game2, game1.name);
		
		
		
		if(contact.getFixtureA().getUserData().equals("FOOT_SENSOR_LOW")){
			GravityRobotPhysicsComponent.numFootContactsLow--;
		}
		else if(contact.getFixtureB().getUserData().equals("FOOT_SENSOR_LOW")){
			GravityRobotPhysicsComponent.numFootContactsLow--;
		}
		
		if(contact.getFixtureA().getUserData().equals("FOOT_SENSOR_UP")){
			GravityRobotPhysicsComponent.numFootContactsUp--;
		}
		else if(contact.getFixtureB().getUserData().equals("FOOT_SENSOR_UP")){
			GravityRobotPhysicsComponent.numFootContactsUp--;
		}
		
	}

	@Override
	public void preSolve(Contact contact, Manifold oldManifold) {
		
		
	}

	@Override
	public void postSolve(Contact contact, ContactImpulse impulse) {
		
		
	}

}
